package _image

import (
	"bytes"
	"image"
	"image/jpeg"
	"io"
)

type jpegHelper struct {
	Quality int
}

func (r jpegHelper) Decode(data []byte) (image.Image, error) {
	return jpeg.Decode(bytes.NewReader(data))
}
func (r jpegHelper) Encode(writer io.Writer, img image.Image) error {
	return jpeg.Encode(writer, img, &jpeg.Options{
		Quality: r.Quality,
	})
}

// func (r jpegHelper) Encode(img image.Image) (bytes.Buffer, error) {
// 	buf := bytes.Buffer{}
// 	err := jpeg.Encode(&buf, img, &jpeg.Options{
// 		Quality: r.Quality,
// 	})
// 	return buf, err
// }

func (r jpegHelper) SetQuality(quality int) jpegHelper {
	r.Quality = quality
	return r
}
